package huzh.foundation.pool.threadpool;

/**
 *<p>title:ConsumerTie</p>
 *<p>description:</p>
 * @since 2014-6-7
 * @author huzh
 * @version 1.0
 */
public class ConsumerTie implements Runnable{
    /**pool*/
    private ThreadPool pool = null;
    /**delegate*/
    private Consumer delegate = null;

    /**
     * @param pool
     * @param delegate
     */
    public ConsumerTie(ThreadPool pool, Consumer delegate){
        this.pool = pool;
        this.delegate = delegate;
    }

    /**
     * 
     */
    public void run() {
        while (this.pool.isRunning()) {
            Object job = this.pool.getJob();
            if (job == null){
                return;
            }
            try{
                this.delegate.doWork(job);
            }catch (Exception e) {
                this.pool.debug("doWork has Exception: " + e);
            }
        }
    }
}
